home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume8 / smile < prev    next >
Encoding:
Text File  |  1989-09-30  |  24.8 KB  |  987 lines

  1. Newsgroups: comp.sources.misc
  2. organization: Organization for Much More Organization, Inc.
  3. keywords: Line Editor for dumb terminals
  4. subject: v08i063: SMiLE = Simple MIni Line Editor
  5. from: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6. Reply-To: acliu%skat.usc.edu@usc.edu (Alejandro Liu)
  7.  
  8. Posting-number: Volume 8, Issue 63
  9. Submitted-by: acliu%skat.usc.edu@usc.edu (Alejandro Liu)
  10. Archive-name: smile
  11.  
  12. SMiLE -- Simple MIni Line Editor
  13. --------------------------------
  14.  
  15. This program was originally intended to be used in a BBS program, but
  16. I got lazy and didn't write the BBS.  The idea of this program is to
  17. provide a very easy to use and rather "powerful" Line Editor with very
  18. little terminal support.  This program was orginially written for a
  19. Commodore 64, so it should be rather easy to port to other system.
  20. This current version is a Unix BSD type system.  (Actually Sun OS
  21. 4.0.?).  I haven't tested if it compiles on other system, but It
  22. SHOULD!
  23.  
  24. You can include this program in your programs as long as you give me
  25. credit and send me a E-mail postcard!   And you can hack it as much as
  26. you like provide it you keep the copyright notice and redistribut it
  27. unmodified (You can distribute your changes in a DIFF file though!)
  28.  
  29.             Alejandro Liu <acliu@skat.usc.edu>
  30.  
  31. #!/bin/sh
  32. # This is a shell archive, meaning:
  33. # 1. Remove everything above the #!/bin/sh line.
  34. # 2. Save the resulting text in a file.
  35. # 3. Execute the file with /bin/sh (not csh) to create the files:
  36. #    smile.c
  37. #    bsd_tty.h
  38. #    smile.h
  39. #    smile_main.c
  40. #    suntty.c
  41. #    Makefile
  42. #    README
  43. #    smile.man
  44. # This archive created: Fri Sep 29 03:14:38 1989
  45. export PATH; PATH=/bin:$PATH
  46. echo shar: extracting "'smile.c'" '(10091 characters)'
  47. if test -f 'smile.c'
  48. then
  49.     echo shar: over-writing existing file "'smile.c'"
  50. fi
  51. sed 's/^X//' << \SHAR_EOF > 'smile.c'
  52. X/* SMiLE -- Simple MIni Line Editor
  53. X   Copyright (C) 1989 By Alejandro Liu
  54. X   You are given permission to Freely Copy and distribute this program
  55. X   in its unmodifed form provided that this copyright notice is included.
  56. X */
  57. X
  58. X#include "smile.h"
  59. X#include "bsd_tty.h"
  60. X#include <ctype.h>
  61. X#include <stdio.h>
  62. X#include <strings.h>
  63. X
  64. X#define TRUE       1
  65. X#define FALSE      0
  66. X#define TSTR     100
  67. X
  68. Xmakebar(width)
  69. Xchar width;
  70. X{
  71. X  int i;
  72. X  for (i = 0;i<width;i++) {
  73. X    if (i%8)
  74. X      prtchr('-');
  75. X    else
  76. X      prtchr('!');
  77. X  };
  78. X  if ((width-1)%8)
  79. X    prtchr('!');
  80. X  prtchr(NEWLIN);
  81. X}
  82. X
  83. Xsmile_intro(width)
  84. Xint width;
  85. X{
  86. X  prtstr("\n");
  87. X  prtstr("SMiLE -- Simple MIni Line Editor        (C) By Alejandro Liu Aug 1989\n");
  88. X  prtstr("Press ESC (CTRL+[) for menu.            CTRL+X to exit SMiLE\n");
  89. X  prtstr("   ");
  90. X  makebar(width);
  91. X}
  92. X
  93. Xint smile(head,wwrap,width)
  94. Xed_line *head;
  95. Xchar wwrap,width;
  96. X{
  97. X  ed_line *current, *temp;
  98. X  char c_buf[TSTR], c_lin, c_col, key, i, j;
  99. X  extern char smile_menu();
  100. X
  101. X  c_col = 0;
  102. X  c_lin = 1;
  103. X  current = head;
  104. X  smile_intro(width);
  105. X  pull(&c_col, c_buf, current);
  106. X  showlin(c_lin,c_buf,c_col);
  107. X
  108. X  for (;;) {
  109. X    key = 127 & getkey();
  110. X    switch (key) {
  111. X      case PREV_L:
  112. X        if (c_lin-1) {
  113. X          c_lin--;
  114. X          push(c_buf,current);
  115. X          temp = current->previous;
  116. X      current = temp;
  117. X          if (current == NULL) current = head;
  118. X          pull(&c_col, c_buf, current);
  119. X          prtchr(NEWLIN);
  120. X          showlin(c_lin,c_buf, c_col);
  121. X        }
  122. X        else
  123. X          beep();
  124. X        break;
  125. X      case NEXT_L:
  126. X        if (current->next == NULL)
  127. X          beep();
  128. X        else {
  129. X          c_lin++;
  130. X          push(c_buf, current);
  131. X          temp = current->next;
  132. X      current = temp;
  133. X          pull(&c_col, c_buf, current);
  134. X          prtchr(NEWLIN);
  135. X          showlin(c_lin,c_buf,c_col);
  136. X        }
  137. X        break;
  138. X      case INSER_L:
  139. X      case INSERT_L:
  140. X        insertl(current);
  141. X        push(c_buf,current);
  142. X        temp = current->next;
  143. X    current = temp;
  144. X        current->len = 0;
  145. X        c_col = 0;
  146. X        c_lin++;
  147. X        c_buf[0] = 0;
  148. X        prtchr(NEWLIN);
  149. X        showlin(c_lin,c_buf,c_col);
  150. X        break;
  151. X      case LEFT_C:
  152. X        if (c_col) {
  153. X          c_col--;
  154. X          backspace(1);
  155. X        }
  156. X        else
  157. X          beep();
  158. X        break;
  159. X      case RIGHT_C:
  160. X        if (c_col == current->len)
  161. X          beep();
  162. X        else {
  163. X          putchar(c_buf[c_col]);
  164. X          c_col++;
  165. X        }
  166. X        break;
  167. X      case DEL_00:
  168. X      case DEL_01:
  169. X      case DEL_02:
  170. X        if (c_col) {
  171. X          if (c_col == current->len) {
  172. X            delete(1);
  173. X            c_buf[c_col--] = 0;
  174. X            (current->len)--;
  175. X          }
  176. X          else {
  177. X            delete(1);
  178. X            for (i = c_col; i<=current->len;i++) {
  179. X              c_buf[i-1] = c_buf[i];
  180. X              if (c_buf[i])
  181. X                prtchr(c_buf[i]);
  182. X              else
  183. X                prtchr(' ');
  184. X            }
  185. X        backspace((current->len) - c_col + 1);
  186. X            c_col--;
  187. X            current->len--;
  188. X          }
  189. X        }
  190. X        else
  191. X          beep();
  192. X        break;
  193. X      case KILL_L:
  194. X        if (c_col == current->len) {
  195. X          if (current->next) {
  196. X        char *mirage;
  197. X        temp = current->next;
  198. X        delete(c_col + 3);
  199. X        c_col = strlen(c_buf) + strlen(temp->data);
  200. X        mirage = (char *)malloc(c_col + 1);
  201. X        strcpy(mirage,c_buf);
  202. X        strcat(mirage,temp->data);
  203. X            current->next = temp->next;
  204. X            free(temp->data);
  205. X            free(temp);
  206. X            if (temp = current->next)
  207. X          temp->previous = current;
  208. X        if (c_col >= width) {
  209. X          c_col = width -1;
  210. X          mirage[c_col] = 0;
  211. X        }
  212. X        current->len = c_col;
  213. X        strcpy(c_buf,mirage);
  214. X        free(mirage);
  215. X            showlin(c_lin, c_buf, c_col);
  216. X      }
  217. X          else
  218. X        beep();
  219. X        }
  220. X        else {
  221. X          for (i=c_col;i<current->len;i++)
  222. X            prtchr(' ');
  223. X          backspace(current->len - c_col);
  224. X          c_buf[current->len = c_col] = 0;
  225. X        }
  226. X        break;
  227. X      case MSG_LST:
  228. X        push(c_buf,current);
  229. X        listmsg(width, head);
  230. X        showlin(c_lin, c_buf, c_col);
  231. X        break;
  232. X      case PREVIEW:
  233. X        push(c_buf,current);
  234. X        preview(width, head);
  235. X        showlin(c_lin, c_buf, c_col);
  236. X        break;
  237. X      case EXIT:
  238. X        push(c_buf, current);
  239. X        return(NORMAL_SAVE);
  240. X      case MENU:
  241. X        push(c_buf,current);
  242. X        if (i = smile_menu(head,FULL_MENU, &wwrap, &width, MENU))
  243. X          if ((i == NORMAL_SAVE) || (i == QUICK_SAVE) || (i == ABORT)) {
  244. X            push(c_buf,current);
  245. X            return(i);
  246. X          }
  247. X        showlin(c_lin,c_buf,c_col);
  248. X        break;
  249. X      case DOTKEY0:
  250. X      case DOTKEY1:
  251. X        if (c_col == 0) {
  252. X          push(c_buf,current);
  253. X          if (i = smile_menu(head,DOT_MENU, &wwrap, &width, key)) {
  254. X            switch (i) {
  255. X              case NORMAL_SAVE:
  256. X              case QUICK_SAVE:
  257. X              case ABORT:
  258. X                push(c_buf,current);
  259. X                return(i);
  260. X              case DOTKEY0:
  261. X              case DOTKEY1:
  262. X                insertc(c_buf, &c_col, &(current->len), i);
  263. X        delete(1);
  264. X                break;
  265. X            }
  266. X          }
  267. X          showlin(c_lin,c_buf,c_col);
  268. X      break;
  269. X        }
  270. X      default:
  271. X        if ((31<key)&&(key<127)) {
  272. X          if (c_col == width) {
  273. X            if (wwrap) {
  274. X              i = c_col;
  275. X              while (i&&(c_buf[i--]!=32));
  276. X              if (i) {
  277. X        if ((c_col-i-1)>0)
  278. X          delete(c_col-i-1);
  279. X                c_buf[++i] = 0;
  280. X                insertl(current);
  281. X                push(c_buf,current);
  282. X                current = current->next;
  283. X                c_lin++;
  284. X                push(&c_buf[i+1], current);
  285. X                pull(&c_col, c_buf, current);
  286. X                c_col = current->len;
  287. X                prtchr(NEWLIN);
  288. X                showlin(c_lin,c_buf,c_col);
  289. X              }
  290. X              else {
  291. X                insertl(current);
  292. X                push(c_buf, current);
  293. X                current = current->next;
  294. X                current->len = 0;
  295. X                c_col = 0;
  296. X                c_lin++;
  297. X                c_buf[0]= 0;
  298. X                prtchr(NEWLIN);
  299. X                showlin(c_lin,c_buf,c_col);
  300. X              }
  301. X              insertc(c_buf,&c_col, &(current->len),key);
  302. X            }
  303. X            else
  304. X              beep();
  305. X          }
  306. X          else
  307. X            insertc(c_buf, &c_col, &(current->len),key);
  308. X        }
  309. X        else
  310. X          beep();
  311. X    }
  312. X  }
  313. X}
  314. X
  315. Xinsertc(buffer, col, len, key)
  316. Xchar buffer[], *col, *len, key;
  317. X{
  318. X  buffer[*col] = key;
  319. X  if ((*col)++ == (*len))
  320. X    buffer[++(*len)] = 0;
  321. X  prtchr(key);
  322. X}
  323. X
  324. Xbackspace(rept)
  325. Xchar rept;
  326. X{
  327. X  while (rept--)
  328. X    prtchr(8);
  329. X}
  330. X
  331. Xdelete(rept)
  332. Xchar rept;
  333. X{
  334. X  while (rept--) {
  335. X    prtchr(8);
  336. X    prtchr(' ');
  337. X    prtchr(8);
  338. X  }
  339. X}
  340. X
  341. Xshowlin(line,buffer,column)
  342. Xchar line, column, *buffer;
  343. X{
  344. X  char leng;
  345. X  printf("%2d>",line);
  346. X  prtstr(buffer);
  347. X  leng = strlen(buffer);
  348. X  if (leng != column)
  349. X    backspace(leng-column);
  350. X}
  351. X
  352. X
  353. Xchar smile_menu(head,type, wrap, width, nkey)
  354. Xed_line *head;
  355. Xchar type, *wrap, *width, nkey;
  356. X{
  357. X  char key, *jet;
  358. X  extern char *getstr();
  359. X  if (type == FULL_MENU) {
  360. X    prtstr("\nSMiLE -- Simple MIni Line Editor MENU   (C) Aug 1989 Alejandro Liu\n\n");
  361. X    prtstr("S - Quick Save      A - Abort Editor    L - List Text       V - Preview Text\n");
  362. X    prtstr("W - Wrd Wrp Toggle  N - Screen Width    H - Help Screen     C - Check Spelling\n");
  363. X    prtstr("Command -->");
  364. X  }
  365. X  else
  366. X    prtstr("Command: ");
  367. X  key = getkey();
  368. X  if (isupper(key))
  369. X    key = tolower(key);
  370. X  switch(key) {
  371. X    case DOTSAV:
  372. X      prtstr("Save Message\n");
  373. X      return(QUICK_SAVE);
  374. X    case DOTHLP:
  375. X      smile_help(*wrap,*width);
  376. X      break;
  377. X    case DOTABT:
  378. X      prtstr("Abort Message\n");
  379. X      return(ABORT);
  380. X    case DOTLST:
  381. X      prtstr("List Message\n");
  382. X      listmsg(*width,head);
  383. X      break;
  384. X    case DOTPVW:
  385. X      prtstr("Preview Message\n");
  386. X      preview(*width,head);
  387. X      break;
  388. X    case DOTWRW:
  389. X      if (*wrap) {
  390. X        *wrap = FALSE;
  391. X        prtstr("Word Wrap Is Off\n");
  392. X      }
  393. X      else {
  394. X        *wrap = TRUE;
  395. X        prtstr("Word Wrap Is On\n");
  396. X      }
  397. X      break;
  398. X    case DOTFNY:
  399. X      prtstr("Funny Command\n");
  400. X      prtstr("A Funny thing happened to me on my way  to the forum... \n");
  401. X      prtstr("I Got there! hahahaha\n");
  402. X      break;
  403. X    case DOTSPC:
  404. X      prtstr("Check Spelling\n");
  405. X      prtstr("SMiLE Spell Checker\n");
  406. X      prtstr("Sorry, the dictionary has been erased\n");
  407. X      break;
  408. X    case DOTCWD:
  409. X      prtstr("Max Col? --> ");
  410. X      jet = getstr();
  411. X      *width = atoi(jet);
  412. X      prtstr("\nScreen Width Set to = ");
  413. X      printf("%d",*width);
  414. X      prtchr(NEWLIN);
  415. X      break;
  416. X    default:
  417. X      if ((type != FULL_MENU)&&(nkey == key)) {
  418. X        delete(13);
  419. X        return(key);
  420. X      }
  421. X      else {
  422. X        beep();
  423. X        prtstr("Unrecognized Command\n");
  424. X      }
  425. X  }
  426. X  return(0);
  427. X}
  428. X
  429. Xlistmsg(width,head)
  430. Xchar width;
  431. Xed_line *head;
  432. X{
  433. X  char cnt = 1;
  434. X  prtstr("SMiLE File Lister\n   ");
  435. X  makebar(width);
  436. X  while (head) {
  437. X    if (((2+cnt)%24)==0)
  438. X      pause();
  439. X    printf("%2d>",cnt++);
  440. X    prtstr(head->data);
  441. X    prtchr(NEWLIN);
  442. X    head = head->next;
  443. X  }
  444. X  prtchr(NEWLIN);
  445. X}
  446. X
  447. Xpreview(width,head)
  448. Xchar width;
  449. Xed_line *head;
  450. X{
  451. X  char cnt = 3;
  452. X  prtstr("SMiLE File Previewer\n");
  453. X  makebar(width);
  454. X  while (head) {
  455. X    if (((cnt++)%24)==0)
  456. X      pause();
  457. X    prtstr(head->data);
  458. X    prtchr(NEWLIN);
  459. X    head = head->next;
  460. X  }
  461. X  prtchr(NEWLIN);
  462. X}
  463. X
  464. Xinsertl(ptr)
  465. Xed_line *ptr;
  466. X{
  467. X  ed_line *tmp, *tmp2, bogus;
  468. X  tmp = (ed_line *)malloc(sizeof(bogus));
  469. X  tmp->previous = ptr;
  470. X  tmp2 = tmp->next = ptr->next;
  471. X  ptr->next = tmp;
  472. X  if (tmp2)
  473. X    tmp2->previous = tmp;
  474. X  tmp->data = (char *)malloc(2);
  475. X  tmp->len = 0;
  476. X  *(tmp->data) = 0;
  477. X}
  478. X
  479. Xpull(col,buf,cur)
  480. Xchar *col, *buf;
  481. Xed_line *cur;
  482. X{
  483. X  strcpy(buf,cur->data);
  484. X  cur->len = strlen(buf);
  485. X  if (*col>(cur->len))
  486. X    *col = cur->len;
  487. X}
  488. X
  489. Xpush(buf,cur)
  490. Xchar *buf;
  491. Xed_line *cur;
  492. X{
  493. X  free(cur->data);
  494. X  cur->len = strlen(buf);
  495. X  cur->data = (char *)malloc((cur->len) + 1);
  496. X  strcpy(cur->data,buf);
  497. X}
  498. X
  499. Xpause()
  500. X{
  501. X  prtstr("* MORE *");
  502. X  beep();
  503. X  getkey();
  504. X  delete(8);
  505. X}
  506. SHAR_EOF
  507. if test 10091 -ne "`wc -c 'smile.c'`"
  508. then
  509.     echo shar: error transmitting "'smile.c'" '(should have been 10091 characters)'
  510. fi
  511. echo shar: extracting "'bsd_tty.h'" '(370 characters)'
  512. if test -f 'bsd_tty.h'
  513. then
  514.     echo shar: over-writing existing file "'bsd_tty.h'"
  515. fi
  516. sed 's/^X//' << \SHAR_EOF > 'bsd_tty.h'
  517. X/* SMiLE -- Simple MIni Line Editor
  518. X   Copyright (C) 1989 By Alejandro Liu
  519. X   You are given permission to Freely Copy and distribute this program
  520. X   in its unmodifed form provided that this copyright notice is included.
  521. X */
  522. X
  523. X#define prtchr(dta)    putchar(dta)
  524. X#define NEWLIN        '\n'
  525. X#define beep()        prtchr(7)
  526. X#define prtstr(string)    printf(string)
  527. X#define getkey()    getchar()
  528. SHAR_EOF
  529. if test 370 -ne "`wc -c 'bsd_tty.h'`"
  530. then
  531.     echo shar: error transmitting "'bsd_tty.h'" '(should have been 370 characters)'
  532. fi
  533. echo shar: extracting "'smile.h'" '(1175 characters)'
  534. if test -f 'smile.h'
  535. then
  536.     echo shar: over-writing existing file "'smile.h'"
  537. fi
  538. sed 's/^X//' << \SHAR_EOF > 'smile.h'
  539. X/* SMiLE -- Simple MIni Line Editor
  540. X   Copyright (C) 1989 By Alejandro Liu
  541. X   You are given permission to Freely Copy and distribute this program
  542. X   in its unmodifed form provided that this copyright notice is included.
  543. X */
  544. X
  545. X#define PREV_L          16
  546. X#define NEXT_L          14
  547. X#define INSER_L         13
  548. X#define INSERT_L        10
  549. X#define LEFT_C           2
  550. X#define RIGHT_C          6
  551. X#define DEL_00           8
  552. X#define DEL_01         127
  553. X#define DEL_02          20
  554. X#define KILL_L          11
  555. X#define MSG_LST         12
  556. X#define PREVIEW         22
  557. X#define EXIT            24
  558. X#define MENU            27
  559. X#define DOTKEY0         '.'
  560. X#define DOTKEY1         '/'
  561. X#define DOTSAV          's'
  562. X#define DOTHLP          'h'
  563. X#define DOTABT          'a'
  564. X#define DOTLST          'l'
  565. X#define DOTPVW          'v'
  566. X#define DOTWRW          'w'
  567. X#define DOTFNY          'f'
  568. X#define DOTSPC          'c'
  569. X#define DOTCWD          'n'
  570. X
  571. Xstruct ED_line {
  572. X  struct ED_line *previous;
  573. X  struct ED_line *next;
  574. X  char len;
  575. X  char *data;
  576. X};
  577. X
  578. Xtypedef struct ED_line ed_line;
  579. X
  580. X#define FULL_MENU       0
  581. X#define DOT_MENU        1
  582. X
  583. X#define NORMAL_SAVE     1
  584. X#define QUICK_SAVE      2
  585. X#define ABORT           3
  586. SHAR_EOF
  587. if test 1175 -ne "`wc -c 'smile.h'`"
  588. then
  589.     echo shar: error transmitting "'smile.h'" '(should have been 1175 characters)'
  590. fi
  591. echo shar: extracting "'smile_main.c'" '(3320 characters)'
  592. if test -f 'smile_main.c'
  593. then
  594.     echo shar: over-writing existing file "'smile_main.c'"
  595. fi
  596. sed 's/^X//' << \SHAR_EOF > 'smile_main.c'
  597. X/* SMiLE -- Simple MIni Line Editor
  598. X   Copyright (C) 1989 By Alejandro Liu
  599. X   You are given permission to Freely Copy and distribute this program
  600. X   in its unmodifed form provided that this copyright notice is included.
  601. X */
  602. X
  603. X#include "bsd_tty.h"
  604. X#include "smile.h"
  605. X#include <stdio.h>
  606. X
  607. Xmain(argc,argv)
  608. Xint argc;
  609. Xchar *argv[];
  610. X{
  611. X  int x;
  612. X  extern int smile();
  613. X  ed_line head, *basura;
  614. X  char width, tk[256];
  615. X  FILE *ants;
  616. X
  617. X  init_tty();
  618. X  if ((argc < 2)||(argc > 3)) {
  619. X    fprintf(stderr, "Usage: %s file [line lenght]\n",argv[0]);
  620. X    restore_tty();
  621. X    exit(1);
  622. X  }
  623. X  width = 35;
  624. X  if (argc == 3)
  625. X    width = atoi(argv[2]);
  626. X  if ((ants = fopen(argv[1],"r")) == NULL) {
  627. X    head.previous = head.next = NULL;
  628. X    head.data = (char *)malloc(2);
  629. X    head.len = *(head.data) = 0;
  630. X  }
  631. X  else {
  632. X    head.previous = NULL;
  633. X    basura = &head;
  634. X  loop:
  635. X    if (fgets(tk, width, ants)) {
  636. X      basura->len = strlen(tk);
  637. X      tk[--(basura->len)] = 0;
  638. X      basura->data = (char *)malloc(basura->len + 1);
  639. X      strcpy(basura->data,tk);
  640. X      basura->next = (ed_line *)malloc(sizeof(head));
  641. X      (basura->next)->previous = basura;
  642. X      basura = basura->next;
  643. X      goto loop;
  644. X    }
  645. X    else {
  646. X      basura->next = NULL;
  647. X      basura->len = 0;
  648. X      basura->data = (char *)malloc(2);
  649. X      *(basura->data) = 0;
  650. X    }
  651. X    fclose(ants);
  652. X  }
  653. X  x = smile(&head, 1, width);
  654. X  if (x == ABORT) {
  655. X    prtstr("SMiLE Aborted... Changes Discarded\n");
  656. X  }
  657. X  else {
  658. X    prtstr("SMiLE saving File\n");
  659. X    if (ants = fopen(argv[1],"w")) {
  660. X      basura = &head;
  661. X      while (basura) {
  662. X    fprintf(ants,"%s\n",basura->data);
  663. X    basura = basura->next;
  664. X      }
  665. X      fclose(ants);
  666. X    }
  667. X    else
  668. X      fprintf(stderr,"%s: can not write to file %s\n",argv[0],argv[1]);
  669. X  }
  670. X  restore_tty();
  671. X}
  672. Xsmile_help(wwst,width)
  673. Xchar wwst,width;
  674. X{
  675. X  prtstr("SMiLE Help SubSystem\n\n");
  676. X  prtstr("Current Screen Width = ");
  677. X  printf("%2d",width);
  678. X  prtstr("  Word Wrap is ");
  679. X  if (wwst)
  680. X    prtstr("enabled\n");
  681. X  else
  682. X    prtstr("disabled\n");
  683. X  prtstr("SMiLE -- Simple MIni Line Editor\n\n");
  684. X  prtstr("This   is a  simple   mini line editor, suitable for editing  messages for mail\n");
  685. X  prtstr("or BBS  posts.  It  has  two integrated command  sets for maximum compatibilty.\n");
  686. X  prtstr("First  Command set is the SMiLE command set,  that   supports  Easy Multi  line\n");
  687. X  prtstr("editing  with easy cursor control,  and the other is a C-Net or Color  BBS, dot\n");
  688. X  prtstr("command or slash command set.\n");
  689. X  prtstr("The Slash and  Command Set of C-Net and Color BBS is  not completely  supported\n");
  690. X  prtstr("except for the most common commands.\n");
  691. X  pause();
  692. X  prtstr("The  New  SMiLE commands that allow all the powerful SMiLE features are:\n");
  693. X  prtstr("CTRL + N   Next Line                    CTRL + P   Previous Line\n");
  694. X  prtstr("CTRL + B   Backward Char                CTRL + F   Forward Char\n");
  695. X  prtstr("CTRL + K   Kill Line                    CTRL + L   List The Text\n");
  696. X  prtstr("CTRL + A   Previews Text                CTRL + [   ESC Key, invokes SMiLE Menu\n");
  697. X  prtstr("Typing   . or / at   the beggining of a Line enters  the QUICK Menu Mode.  i.e.\n");
  698. X  prtstr("you will be prompted for a  option from the SMiLE  menu, but   no menu will  be\n");
  699. X  prtstr("displayed.     (C-Net/Color         BBS Compatibility command)\n");
  700. X}
  701. SHAR_EOF
  702. if test 3320 -ne "`wc -c 'smile_main.c'`"
  703. then
  704.     echo shar: error transmitting "'smile_main.c'" '(should have been 3320 characters)'
  705. fi
  706. echo shar: extracting "'suntty.c'" '(1864 characters)'
  707. if test -f 'suntty.c'
  708. then
  709.     echo shar: over-writing existing file "'suntty.c'"
  710. fi
  711. sed 's/^X//' << \SHAR_EOF > 'suntty.c'
  712. X/* SMiLE -- Simple MIni Line Editor
  713. X   Copyright (C) 1989 By Alejandro Liu
  714. X   You are given permission to Freely Copy and distribute this program
  715. X   in its unmodifed form provided that this copyright notice is included.
  716. X */
  717. X
  718. X#include <stdio.h>
  719. X#include <sys/ioctl.h>
  720. X#include "bsd_tty.h"
  721. X#define DEL_00        127
  722. X#define DEL_01         20
  723. X#define DEL_02          8
  724. X#define LEFT_C          2
  725. X#define RIGHT_C          6
  726. X#define DONE0         13
  727. X#define DONE1         10
  728. X
  729. X#define STDIN   0
  730. X#define STDOUT  1
  731. X#define STDERR  2
  732. X#define ERROR    -1
  733. X#define TSTR    300
  734. X
  735. Xstruct sgttyb old;
  736. X
  737. Xinit_tty()
  738. X{
  739. X  struct sgttyb new;
  740. X  if (ioctl(STDIN, TIOCGETP, &old) == ERROR) {
  741. X    perror("Can not get Terminal parameters -- ioctl");
  742. X    exit(1);
  743. X  }
  744. X  new.sg_ospeed = old.sg_ospeed;
  745. X  new.sg_ispeed = old.sg_ispeed;
  746. X  new.sg_flags  = ((old.sg_flags | CBREAK) & ~ECHO) & ~TANDEM;
  747. X  if (ioctl(STDIN, TIOCSETN, &new) == ERROR) {
  748. X    perror("Can not set Terminal Characteristics -- ioctl");
  749. X    exit(1);
  750. X  }
  751. X}
  752. X
  753. Xrestore_tty()
  754. X{
  755. X  if (ioctl(STDIN, TIOCSETN, &old) == ERROR) {
  756. X    perror("Can not restore Terminal Characteristics -- ioctl");
  757. X    exit(1);
  758. X  }
  759. X}
  760. X
  761. Xchar *getstr()
  762. X{
  763. X  char *tmp1, *tmp2;
  764. X  char key;
  765. X
  766. X  tmp1 = tmp2 = (char *)malloc(TSTR);
  767. X  *(tmp1) = 0;
  768. X  for (;;) {
  769. X    key = 127 & getkey();
  770. X    switch (key) {
  771. X      case DEL_00:
  772. X      case DEL_01:
  773. X      case DEL_02:
  774. X        if (tmp1 == tmp2)
  775. X      beep();
  776. X    else {
  777. X      delete(1);
  778. X      *(--tmp1) = 0;
  779. X    }
  780. X    break;
  781. X      case LEFT_C:
  782. X    if (tmp1 == tmp2)
  783. X      beep();
  784. X    else {
  785. X      backspace(1);
  786. X      --tmp1;
  787. X    }
  788. X    break;
  789. X      case RIGHT_C:
  790. X    if (*tmp1)
  791. X      prtchr(*(tmp1++));
  792. X    else
  793. X      beep();
  794. X    break;
  795. X      case DONE0:
  796. X      case DONE1:
  797. X    key = strlen(tmp2) + 1;
  798. X    tmp1 = (char *)malloc(key);
  799. X    strcpy(tmp1,tmp2);
  800. X    free(tmp2);
  801. X    return(tmp1);
  802. X      default:
  803. X    if ((31<key)&&(key<127)) {
  804. X      if (!(*tmp1))
  805. X        *(tmp1+1) = 0;
  806. X      *(tmp1++) = key;
  807. X      prtchr(key);
  808. X    }
  809. X    else
  810. X      beep();
  811. X    }
  812. X  }
  813. X}
  814. SHAR_EOF
  815. if test 1864 -ne "`wc -c 'suntty.c'`"
  816. then
  817.     echo shar: error transmitting "'suntty.c'" '(should have been 1864 characters)'
  818. fi
  819. echo shar: extracting "'Makefile'" '(440 characters)'
  820. if test -f 'Makefile'
  821. then
  822.     echo shar: over-writing existing file "'Makefile'"
  823. fi
  824. sed 's/^X//' << \SHAR_EOF > 'Makefile'
  825. X# Primitive Makefile. Not that great but helps!
  826. X
  827. Xsmile: smile.o smile_main.o suntty.o
  828. X    cc -O smile.o smile_main.o suntty.o -o smile
  829. X
  830. Xsmile.o: smile.c smile.h bsd_tty.h
  831. X    cc -c -O smile.c
  832. X
  833. Xsmile_main.o: smile_main.c smile.h
  834. X    cc -c -O smile_main.c
  835. X
  836. Xsuntty.o: suntty.c
  837. X    cc -c -O suntty.c
  838. X
  839. Xlint:
  840. X    lint smile.c smile_main.c suntty.c
  841. X
  842. Xshar:
  843. X    shar -c -p X smile.c bsd_tty.h smile.h smile_main.c suntty.c \
  844. X    Makefile README smile.man > smile.shar 
  845. X
  846. SHAR_EOF
  847. if test 440 -ne "`wc -c 'Makefile'`"
  848. then
  849.     echo shar: error transmitting "'Makefile'" '(should have been 440 characters)'
  850. fi
  851. echo shar: extracting "'README'" '(869 characters)'
  852. if test -f 'README'
  853. then
  854.     echo shar: over-writing existing file "'README'"
  855. fi
  856. sed 's/^X//' << \SHAR_EOF > 'README'
  857. XSMiLE -- Simple MIni Line Editor
  858. X--------------------------------
  859. X
  860. XThis program was originally intended to be used in a BBS program, but
  861. XI got lazy and didn't write the BBS.  The idea of this program is to
  862. Xprovide a very easy to use and rather "powerful" Line Editor with very
  863. Xlittle terminal support.  This program was orginially written for a
  864. XCommodore 64, so it should be rather easy to port to other system.
  865. XThis current version is a Unix BSD type system.  (Actually Sun OS
  866. X4.0.?).  I haven't tested if it compiles on other system, but It
  867. XSHOULD!
  868. X
  869. XYou can include this program in your programs as long as you give me
  870. Xcredit and send me a E-mail postcard!   And you can hack it as much as
  871. Xyou like provide it you keep the copyright notice and redistribut it
  872. Xunmodified (You can distribute your changes in a DIFF file though!)
  873. X
  874. X            Alejandro Liu <acliu@skat.usc.edu>
  875. X
  876. SHAR_EOF
  877. if test 869 -ne "`wc -c 'README'`"
  878. then
  879.     echo shar: error transmitting "'README'" '(should have been 869 characters)'
  880. fi
  881. echo shar: extracting "'smile.man'" '(2090 characters)'
  882. if test -f 'smile.man'
  883. then
  884.     echo shar: over-writing existing file "'smile.man'"
  885. fi
  886. sed 's/^X//' << \SHAR_EOF > 'smile.man'
  887. X.TH SMILE L
  888. X.SH NAME
  889. XSMiLE \- Simple MIni Line Editor
  890. X.SH SYNTAX
  891. X.B smile 
  892. X.I 
  893. Xfilename [screen width]
  894. X.SH DESCRIPTION
  895. XThis program is a very simple line editor that doesn't use the TermCap
  896. Xor Curses library to do its editing.  It provides "advanced" features
  897. Xlike auto word wrap, and Full line editing.  The main advantage of
  898. X.I smile
  899. Xis that it can be used in almost any CRT terminal, regardless of its
  900. Xtype, as long as it supports the almost universal convention of using
  901. X^H (ASCII 8) as non destructive backspace.
  902. X.SH OPERATION
  903. X.I smile
  904. Xis entered from UNIX by typing the command line followed by a filename
  905. Xand an optional Screen width.  The default is specified during
  906. Xcompilation time and varies from site to site.
  907. X.PP
  908. X.I smile
  909. Xis advertised to be very easy to use, and it has a built in help (sort
  910. Xof) that can be displayed any time.  The commands to know are:
  911. X.br
  912. X.sp
  913. X.nf
  914. Xkey        function
  915. X---        --------
  916. X^N        Next Line
  917. X^P        Previous Line
  918. X^F        Forward Character
  919. X^B        Backward Character
  920. X^K        Kill line
  921. X^A        Previews text
  922. X^L        List Text
  923. XESC        SMILE menu
  924. X.sp
  925. X.fi
  926. X.PP
  927. XAlso,
  928. X.I smile
  929. Xsupports the use of "dot" or "slash" command that are very common on
  930. Xsome BBS programs line editors.  Basicly what they do is at the first
  931. Xcolumn of any line if you press any of those keys you will be prompted
  932. Xfor a menu option.  Pressing "." or "/" again will put a "." or "/" in
  933. Xthe text.
  934. X.PP
  935. XOptions in
  936. X.I smile
  937. Xmenu:
  938. X.br
  939. X.sp
  940. X.nf
  941. XOption        function
  942. X------        --------
  943. X  S        Saves the file
  944. X  A        Abort Editor and discards changes
  945. X  W        Word Wrap Togle
  946. X  N        New Screen Width
  947. X  H        Help Screen
  948. X  C        Check Spelling
  949. X  P        Preview Text
  950. X  L        List Text
  951. X.sp
  952. X.fi
  953. X.SH AUTHOR
  954. XAlejandro Liu
  955. X.SH "SEE ALSO"
  956. Xemacs(1), vi(1), ed(1)
  957. X.SH BUGS
  958. X.I Smile
  959. Xdoesn't support terminals that don't use ^H as  backspace. Also, the
  960. Xprogram will perform strangely of terminals that the ^H performs a
  961. Xdestructive backspace.
  962. X.PP
  963. XThe Spell checker doesn't work.
  964. X.PP
  965. X.I Smile
  966. Xkeeps with the UNIX tradition of optimism by doing very little error
  967. Xchecking!
  968. X.PP
  969. X.I Smile
  970. Xwas originally written for the C-64 (Serious Bug here!) for use in a
  971. XBBS program.
  972. X.br
  973. SHAR_EOF
  974. echo shar: a missing newline was added to "'smile.man'"
  975. if test 2090 -ne "`wc -c 'smile.man'`"
  976. then
  977.     echo shar: error transmitting "'smile.man'" '(should have been 2090 characters)'
  978. fi
  979. #    End of shell archive
  980. exit 0
  981.  
  982. Alejandro Liu
  983. acliu%skat@usc.edu    acliu@skat.usc.edu
  984. (Simple .signature, $CHEAP$)
  985.  
  986.